<template>
	<view class="container">
		<view class="headerNav">
			<u-navbar :title="data.utype == 1 ? '收到投递' : '被关注'"></u-navbar>
			<u-dropdown ref="dropdown" @open="open" @close="close" v-if="data.utype == 1">
				<u-dropdown-item v-model="data.jobVal" :title="data.job_text || '全部职位'" :options="data.jobList"
					@change="change($event,'job')"></u-dropdown-item>
				<u-dropdown-item v-model="data.handleVal" :title="data.handle_text || '处理状态'" :options="data.handleList"
					@change="change($event,'handle')"></u-dropdown-item>
				<u-dropdown-item v-model="data.viewVal" :title="data.view_text || '查看状态'" :options="data.viewList"
					@change="change($event,'view')"></u-dropdown-item>
				<u-dropdown-item v-model="data.sourceVal" :title="data.source_text || '全部来源'" :options="data.sourceList"
					@change="change($event,'source')"></u-dropdown-item>
			</u-dropdown>
		</view>
		<z-paging :fixed="false" :height="data.height" ref="paging" v-model="dataList" @query="getSystemInfoSync"
			created-reload show-refresher-when-reload>
			<view v-if="data.utype == 1">
				<view class="container_ls" v-for="item in dataList" :key="item.id" @click="handleToReusme(item)">
					<view class="u-flex u-row-between">
						<view class="u-flex">
							<view style="position: relative;">
								<u-avatar :src="item.photo_img_src"></u-avatar>
								<view class="badge" v-if="item.is_look == 0"></view>
							</view>
							<view class="u-m-l-28">
								<view class="u-font-32 u-font-weight">{{item.fullname}}</view>
								<view class="u-m-t-16" style="color: #867F7F ;">
									{{`${item.experience_text} | ${item.education_text} | ${item.intention_wage}`}}
								</view>
							</view>
						</view>
						<view class="u-text-right">
							<view class="u-m-b-10 u-font-12" style="color: #867F7F ;">
								{{$u.timeFormat(item.addtime)}}
							</view>
							<u-tag v-if="item.handle_status == 0" text="待处理" mode="dark" type="warning" size="mini" />
							<u-tag v-if="item.handle_status == 1" text="已同意" mode="dark" size="mini" />
							<u-tag v-if="item.handle_status == 2" text="已婉拒" mode="dark" type="error" size="mini" />
						</view>
					</view>
					<view class="u-p-l-30 u-p-r-30">
						<!-- 备注 -->
						<view v-if="item.remark" class="u-m-t-24" style="color:#867F7F">
							{{item.remark}}
						</view>
						<!-- 投递职位 -->
						<view class="container_ls_jobname u-m-t-20">
							投递职位：<text>{{item.jobname}}</text>
						</view>


						<view class="u-flex u-row-right u-m-t-28">
							<view class="container_ls_tag" v-if="item.handle_status == 0"
								@click.stop="handlerAgree(item)">
								同意
							</view>
							<view class="container_ls_tag" v-if="item.handle_status == 0"
								@click.stop="handlerRefuse(item)">
								婉拒
							</view>
							<view class="container_ls_tag" @click.stop="handlerRemark(item)">
								备注
							</view>
							<view class="container_ls_tag" @click.stop="handlerDel(item)">
								删除
							</view>
						</view>
					</view>

				</view>
			</view>
			<view v-if="data.utype == 2">
				<view class="bigNav">
					<view class="newsList" v-for="item in dataList" :key="item.id" @tap="tojob(item.company_id)">
						<view class="newsTop">
							<view class="comname">
								<text class="textcom">{{item.companyname}}</text>
								<image src="/pages/pagesPersonal/static/personal/authentication.png" mode=""></image>
							</view>
							<text>{{getMyDate(item.addtime*1000)}}</text>
						</view>
						<view class="brief">
							<text>{{item.district_text}}</text>
							<text>{{item.scale_text}}</text>
							<text>{{item.nature_text}}</text>
						</view>
						<view class="more">
							<view class="moreleft">
								<!-- <image src="../../../static/personal/footprint.png" mode=""></image> -->
								<text>热招:</text>
								<text style="color: #00D075;">{{item.first_jobname}}</text>
								<text>等{{item.jobnum}}个岗位</text>
							</view>
					
							<text class="moreright">{{item.has_download==0?'未下载':'已下载'}}</text>
						</view>
					</view>
				</view>
			</view>
		</z-paging>
		<!-- 婉拒弹框 -->
		<u-modal v-model="data.isRefuse" title="系统提示" content="确定将处理状态更改为【已婉拒】吗？" show-cancel-button
			@cancel="data.isRefuse = false" @confirm="handlerRefuseConfirm"></u-modal>
		<!-- 备注弹框 -->
		<u-modal v-model="data.isRemark" title="备注" show-cancel-button @cancel="data.isRemark = false"
			@confirm="handlerRemarkConfirm">
			<template v-slot:default>
				<view class="u-p-30">
					<u-input type="textarea" maxlength="50" v-model="data.remark" placeholder="请输入备注内容"
						border></u-input>
				</view>
			</template>
		</u-modal>
		<!-- 删除弹框 -->
		<u-modal v-model="data.isDel" title="系统提示" content="确定删除该简历吗？" show-cancel-button @cancel="data.isDel = false"
			@confirm="handlerDelConfirm"></u-modal>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive
	} from "vue"
	import {
		onReady,
		onShow,
		onLoad
	} from '@dcloudio/uni-app'
	const data = reactive({
		utype: uni.getStorageSync('utype'),
		height: "",
		// 简历信息
		item: {},
		// 婉拒
		isRefuse: false,
		// 备注
		isRemark: false,
		remark: '',
		// 职位
		jobVal: 0,
		job_text: '',
		jobList: [],
		// 处理状态
		handleVal: 0,
		handle_text: '',
		handleList: [{
				label: '处理状态',
				value: 0
			},
			{
				label: '待处理',
				value: 1
			},
			{
				label: '已同意',
				value: 2
			},
			{
				label: '已拒绝',
				value: 3
			}
		],
		// 查看状态
		viewVal: 0,
		view_text: '',
		viewList: [{
				label: '查看状态',
				value: 0
			},
			{
				label: '未查看',
				value: 1
			},
			{
				label: '已查看',
				value: 2
			}
		],
		// 全部来源
		sourceVal: 0,
		source_text: '',
		sourceList: [{
				label: '全部来源',
				value: 0
			},
			{
				label: '自主投递',
				value: 1
			},
			{
				label: '委托投递',
				value: 2
			}
		],
		// 筛选条件
		params: {}
	})


	// 获取职位列表数据
	const paging = ref(null)
	let dataList = ref([])
	const getSystemInfoSync = async (pageNo, pageSize) => {
		let params = Object.assign({
			page: pageNo,
			pagesize: pageSize
		}, data.params)
		let res
		if (data.utype == 1) {
			res = await uni.$u.api.getCompanyJobApply({
				params
			})
			data.jobList = res.option_jobs.map(item => {
				return {
					label: item.jobname,
					value: item.id
				}
			})
			data.jobList.unshift({
				label: '全部职位',
				value: 0
			})
		} else {
			res = await uni.$u.api.attention_me({
				params
			})
		}
		paging.value.complete(res.items)
	}
	// 下拉列表
	const dropdown = ref(null)
	const open = (index) => {
		// 展开某个下来菜单时，先关闭原来的其他菜单的高亮
		// 同时内部会自动给当前展开项进行高亮
		dropdown.value.highlight();
	}
	const close = (index) => {
		// 关闭的时候，给当前项加上高亮
		// 当然，您也可以通过监听dropdown-item的@change事件进行处理
		dropdown.value.highlight(index);
	}
	const change = (id, type) => {
		if (type == 'job') {
			data.params.jobid = id  == 0 ? '' : id 
			data.job_text = textFn(id, data.jobList)
		} else if (type == 'handle') {
			data.params.status = id - 1 == -1 ? '' : id - 1
			data.handle_text = textFn(id, data.handleList)
		} else if (type == 'view') {
			data.params.is_look = id - 1 == -1 ? '' : id - 1
			data.view_text = textFn(id, data.viewList)
		} else if (type == 'source') {
			data.params.source = id - 1 == -1 ? '' : id - 1
			data.source_text = textFn(id, data.sourceList)
		}
		paging.value.reload()
	}
	const textFn = (id, list) => {
		let res = list.filter(item => item.value === id)
		return res[0].label
	}
	// 删除
	const handlerDel = (item) => {
		data.item = item
		data.isDel = true
	}
	const handlerDelConfirm = async () => {
		let params = {
			id: data.item.id
		}
		let res = await uni.$u.api.company_jobapply_del(params)
		uni.$u.toast('简历删除成功')
		paging.value.reload()
	}
	// 备注
	const handlerRemark = (item) => {
		data.item = item
		data.isRemark = true
	}
	const handlerRemarkConfirm = async () => {
		if (uni.$u.test.isEmpty(data.remark)) {
			uni.$u.toast('请输入备注内容')
			data.isRemark = true
			return
		}
		let parmas = {
			remark: data.remark,
			resume_id: data.item.resume_id
		}
		let res = await uni.$u.api.remark_resume(parmas)
		data.remark = ''
		uni.$u.toast('备注成功')
		paging.value.reload()
	}
	// 婉拒
	const handlerRefuse = (item) => {
		if (item.audit != 1) return uni.$u.toast('该简历尚未通过审核，不能继续此操作')
		data.item = item
		data.isRefuse = true
	}
	const handlerRefuseConfirm = async () => {
		let params = {
			id: data.item.id
		}
		let res = await uni.$u.api.company_jobapply_set_refuse(params)
		uni.$u.toast('简历处理成功')
		paging.value.reload()
	}
	// 同意
	const handlerAgree = async (item) => {
		if (item.audit != 1) return uni.$u.toast('该简历尚未通过审核，不能继续此操作')
		let params = {
			id: item.id
		}
		let res = await uni.$u.api.company_jobapply_set_agree_pre(params)
		if (res.finish == 1) {
			paging.value.reload()
			uni.$u.toast('简历处理成功')
		} else {
			paging.value.reload()
			uni.$u.route('/pages/pagesHome/detailPages/invitation', {
				fullname: item.fullname,
				resumeid: item.resume_id
			})
		}
	}
	// 去职位详情页
	const handleToReusme = async (item) => {
		if (item.is_look === 0) {
			let params = {
				id: item.id
			}
			let res = await uni.$u.api.company_jobapply_set_looked(params)
			paging.value.reload()
		}
		uni.$u.route('/pages/pagesHome/detailPages/resume', {
			id: item.resume_id,
			jobid: item.jobid,
			jobname: item.jobname
		})
	}

	const tojob = (id, show = false) => {
		uni.$u.route('pages/pagesHome/detailPages/company', {
			id,
			show
		})
	}
	// 获取列表展示高度
	const getListHeight = async () => {
		let res = await uni.$u.getRect('.headerNav');
			data.height = (uni.$u.sys().windowHeight - res.height) + 'px';
	}

	function getMyDate(str) {
		var oDate = new Date(str),
			oYear = oDate.getFullYear(),
			oMonth = oDate.getMonth() + 1,
			oDay = oDate.getDate(),
			oHour = oDate.getHours(),
			oMin = oDate.getMinutes(),
			oSen = oDate.getSeconds(),
			oTime = oYear + '-' + addZero(oMonth) + '-' + addZero(oDay) + ' ' + addZero(oHour) + ':' +
			addZero(oMin) + ':' + addZero(oSen);
		return oTime;
	}
	//补零操作
	function addZero(num) {
		if (parseInt(num) < 10) {
			num = '0' + num;
		}
		return num;
	}

	onReady(() => {
		getListHeight()
	})
</script>

<style lang="scss">
	page,
	body {
		width: 100vw;
		height: 100%;
		background-color: #f8f8f8;
	}

	.headerNav {
		background-color: #fff;
	}

	.container {
		width: 100%;
		height: 100%;

		&_ls {
			background-color: #fff;
			margin-bottom: 10rpx;
			margin-top: 20rpx;
			padding: 32rpx;
			font-size: 26rpx;
			color: #101010;

			&_jobname {
				border-radius: 8rpx;
				background-color: rgba(242, 242, 242, 1);
				text-align: left;
				padding: 15rpx 26rpx;

				text {
					color: #00D075;
				}
			}

			&_tag {
				background-color: rgba(255, 255, 255, 1);
				text-align: center;
				border: 2rpx solid rgba(187, 187, 187, 1);
				margin-left: 18rpx;
				padding: 12rpx 26rpx;
			}
		}

		.bigNav {
			width: 100%;
			font-family: Arial;

			.newsList {
				padding: 50rpx 30rpx 30rpx 30rpx;
				width: 100%;
				background-color: #fff;
				border-radius: 6rpx;
				margin-bottom: 20rpx;

				.newsTop {
					font-weight: bold;
					font-size: 32rpx;
					font-family: Arial;
					display: flex;
					justify-content: space-between;
					align-items: center;

					.comname {
						display: flex;
						align-items: center;
						image {
							width: 70rpx;
							height: 28rpx;
							margin-left: 10rpx;
						}
						.textcom{
							display: inline-block;
							width: 300rpx;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
						}
					}

					text:nth-child(2) {
						font-size: 24rpx;
						color: #867F7F;
						font-weight: normal;
					}
				}

				.brief {
					font-size: 26rpx;
					font-family: Arial;
					color: #867F7F;
					margin: 20rpx 0;
					display: flex;

					text {
						background-color: #f1f1f1;
						// margin: 0 20rpx;
						padding: 15rpx;
						border-radius: 6rpx;
					}
					text:nth-child(2){
						margin: 0 20rpx;
					}
				}

				.more {
					color: #867F7F;
					font-size: 24rpx;
					font-family: Arial;
					display: flex;
					justify-content: space-between;
					align-items: center;
					border-top: 1rpx solid #ccc;
					padding-top: 20rpx;

					.moreleft {
						display: flex;
						align-items: center;
						
						text:nth-child(1) {
							margin-right: 10rpx;
						}
						text:nth-child(2) {
							display: inline-block;
							max-width:350rpx ;
							margin-right: 5rpx;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
						}
					}

					.moreright {
						color: #F26817;
					}

				}
			}
		}

		.badge {
			position: absolute;
			right: 2px;
			top: 2px;
			width: 10px;
			height: 10px;
			background: #ff4c56;
			color: #fff;
			font-size: 10px;
			border-radius: 50%;
			display: flex;
			align-items: center;
			justify-content: center;
		}


	}
	:deep .u-dropdown {
		box-shadow: 0px 0px 7px 0px rgba(0, 0, 0, 0.4) !important;
		background-color: #fff;
		border-bottom: 1rpx solid #ccc;
	}
</style>